//
//  ByCellDayEarningIncome.m
//  mijifen_ios
//
//  Created by mc on 2017/10/26.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByCellDayEarningIncome.h"

@implementation ByCellDayEarningIncome
{
    UIImageView     *_flagImg;
    UIView          *_bgView;
    UILabel         *_priceLabel;
    UILabel         *_shopLabel;
    UILabel         *_subInfoLabel;
    UIView          *_lineView1;
    UILabel         *_redLabel;
    UILabel         *_pointLabel;
    UIView          *_lineView2;
}

+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByCellDayEarningIncome";
    ByCellDayEarningIncome *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.backgroundColor = [UIColor clearColor];
        [self createViews];
    }
    return self;
}

- (void)createViews{
    _bgView = [[UIView alloc] init];
    [self addSubview:_bgView];
    
    _flagImg = [[UIImageView alloc] init];
    [self addSubview:_flagImg];
 
    _priceLabel = [[UILabel alloc] init];
    [_bgView addSubview:_priceLabel];
    
    _shopLabel = [[UILabel alloc] init];
    [_bgView addSubview:_shopLabel];
    
    _subInfoLabel = [[UILabel alloc] init];
    [_bgView addSubview:_subInfoLabel];
    
    _lineView1 = [[UIView alloc] init];
    [_bgView addSubview:_lineView1];
    
    _redLabel = [[UILabel alloc] init];
    [_bgView addSubview:_redLabel];
    
    _pointLabel = [[UILabel alloc] init];
    [_bgView addSubview:_pointLabel];
    
    _lineView2 = [[UIView alloc] init];
    [_bgView addSubview:_lineView2];
}

- (void)setModel:(ByModelDayEarning *)model{
    _model = model;

//    [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.mas_top).offset(5);
//        make.left.equalTo(self.mas_left);
//        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 70));
//    }];
//    _bgView.backgroundColor = [UIColor whiteColor];
    
    // 3 : 4 (45:60)
    [_flagImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(10);
        make.top.equalTo(self.mas_top);
        make.size.mas_equalTo(CGSizeMake(45, 60));
    }];
    _flagImg.image = [UIImage imageNamed:@"DayEarning_shouru"];
    
    // 价格
    CGFloat x = 10 + 45 + 25;
    CGFloat width = (SCREEN_WIDTH - x) / 2;
    [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_bgView.mas_left).offset(x);
        make.top.equalTo(_bgView.mas_top).offset(10);
        make.size.mas_equalTo(CGSizeMake(width, 20));
    }];
    _priceLabel.adjustsFontSizeToFitWidth = YES;
    _priceLabel.font = FONT(18);
    
    // 信息
    [_subInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_priceLabel.mas_left);
        make.top.equalTo(_priceLabel.mas_bottom).offset(10);
        make.size.mas_equalTo(CGSizeMake(width, 20));
    }];
    _subInfoLabel.textColor = [UIColor darkGrayColor];
    _subInfoLabel.font = FONT(14);
    
    // 店名
    [_shopLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_bgView.mas_right).offset(-10);
        make.top.equalTo(_bgView.mas_top).offset((70 - 20) / 2);
        make.size.mas_equalTo(CGSizeMake(width, 20));
    }];
    _shopLabel.adjustsFontSizeToFitWidth = YES;
    _shopLabel.font = FONT(18);
    _shopLabel.textAlignment = NSTextAlignmentRight;
    
    // 线
    [_lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_shopLabel.mas_bottom).offset(25);
        make.left.equalTo(_flagImg.mas_left);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 20, 1));
    }];
    _lineView1.backgroundColor = [UIColor lightGrayColor];
    
    // 红包
    [_redLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_flagImg.mas_left);
        make.top.equalTo(_lineView1.mas_bottom).offset(10);
        make.size.mas_equalTo(CGSizeMake((SCREEN_WIDTH - 20 - 11) / 2, 20));
    }];
    _redLabel.textAlignment = NSTextAlignmentCenter;
    
    
    // 线
    [_lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_redLabel.mas_right);
        make.top.equalTo(_lineView1.mas_bottom).offset(10);
        make.size.mas_equalTo(CGSizeMake(1, 20));
    }];
    _lineView2.backgroundColor = [UIColor lightGrayColor];
    
    // 积分
    [_pointLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_bgView.mas_right).offset(-10);
        make.top.equalTo(_lineView1.mas_bottom).offset(10);
        make.size.mas_equalTo(CGSizeMake((SCREEN_WIDTH - 20 - 11) / 2, 20));
    }];
    _pointLabel.textAlignment = NSTextAlignmentCenter;
    
    [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(10);
        make.left.equalTo(self.mas_left);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 70 + 40));
    }];
    _bgView.backgroundColor = [UIColor whiteColor];

    
    // 测试数据
    _priceLabel.text = [NSString stringWithFormat:@"¥%@",_model.prcie];
    _subInfoLabel.text = _model.resource;
    _shopLabel.text = _model.shop_name;
    _redLabel.text = @"红包抵扣¥50";
    _pointLabel.text = @"积分抵扣¥50";
    
}


@end
